﻿@{
    ViewBag.Title = "OutpatienChargeQuery";
    Layout = "~/Views/Shared/_Index.cshtml";

    var curOpr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();

    string regReportUrl = "";
    string chargeReportUrl = "";
    string ZFinvoiceReportUrl = "";
    string invoicePrintMethod = null; //ActiveX
    string OutpatientChargeDetail= "";
    if (SysConfigReader.Bool("Outpatient_Register_PrintAble") == true)
    {
        //挂号发票报表链接
        regReportUrl = SysConfigReader.OrgReportLink("NewOutpatientRegister");
        OutpatientChargeDetail = SysConfigReader.OrgReportLink("OutpatientChargeDetail");
        invoicePrintMethod = invoicePrintMethod ?? SysConfigReader.String("Outpatient_ChargeFeeInvoice_PrintMethod");
    }
    if (SysConfigReader.Bool("Outpatient_ChargeFee_PrintAble") == true)
    {
        //收费发票报表链接
        chargeReportUrl = SysConfigReader.OrgReportLink("NewOutpatientCharge");
        //收费票据报表链接(自费)
        ZFinvoiceReportUrl = SysConfigReader.OrgReportLink("ZFOutpatientRegister");
        OutpatientChargeDetail = SysConfigReader.OrgReportLink("OutpatientChargeDetail");
        invoicePrintMethod = invoicePrintMethod ?? SysConfigReader.String("Outpatient_ChargeFeeInvoice_PrintMethod");
    }
    var useSfrqFilter = SysConfigReader.Bool("Outpatient_ChargeQuery_UseSfrqFilter");
    var opr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();
    //医保所属地，区分系统将执行何处医保逻辑
    var medicalInsurance = SysConfigReader.String("Outpatient_MedicalInsurance");
    var reportUrl = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportUrl");
    var reportSystemCode = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportSystemCode");
}
<style>
    .form .formTitle {
        position: relative;
        left: 0px;
        text-align: right;
        white-space: nowrap;
        font-weight: normal;
        width: 70px;
        padding-right: 15px;
    }

</style>
@Html.Partial("_YibaoCommonView")
<form name="form1">
    <div class="panel panel-default">
        <div class="panel-heading navb-bg">
            筛选条件
        </div>
        <table class="form">
            <tr>
                <th class="formTitle">病例号/姓名：</th>
                <td class="formValue">
                    <input type="text" class="form-control" id="txtxm" name="txtxm" />
                </td>
                <th class="formTitle">发票号：</th>
                <td class="formValue" colspan="2">
                    <input type="text" class="form-control" id="txtfph" name="txtfph" style="width:40%; float:left;"/>
                    <span style="margin-left:0%;float:left;">至</span>
                    <input type="text" class="form-control" id="txtjsfph" name="txtjsfph" style="width:40%; float:left;" />
                </td>
                <th class="formTitle">中心流水号：</th>
                <td class="formValue">
                    <input type="text" class="form-control" id="txtzxlsh" value="" />
                </td>
                <th class="formTitle">收费员：</th>
                <td class="formValue">
                    <div class="row">
                        <div class="col-md-9">
                            <input type="text" class="form-control" id="txtsyy" value="" />
                        </div>
                        <div class="col-md-3" style="text-align:right;">
                            <input type="button" class="btn btn-default btn-md" style="width:45px" id="btnsyy" value="查询" />
                        </div>
                    </div>
                </td>
                <td style="width:20px"></td>
                <th class="formTitle" id="thCZRQ">操作日期：</th>
                <td class="formValue" colspan="3">
                    <input id="txtCreateTimestart" type="text" class="form-control input-wdatepicker formClearIgnore" style="width:42%; float:left;" value="@DateTime.Now.ToString("yyyy-MM-01")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                    <span style="margin-left:0%;float:left;">—</span>
                    <input id="txtCreateTimeEnd" type="text" class="form-control input-wdatepicker formClearIgnore" style="width :41%;float:left;margin-left:2%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                </td>
                <td class="formValue">
                    <input type="button" id="btn_search" class="btn btn-primary btn-md" style="margin-left:10px;width:40px;" value="查询" />
                </td>
            </tr>
            <tr></tr>
        </table>
    </div>
    <div class="gridPanel">
        <table id="gridJSList"></table>
        <div id="gridPager"></div>
    </div>

    <ul id="myTab" class="nav nav-tabs">
        <li class="active"><a href="#newyj" data-toggle="tab">分类检索明细</a></li>
        <li><a href="#yj" data-toggle="tab">门诊结算明细</a></li>
        <content style="float:right;margin-right:45px ;width:70% ;" id="ctmx">
            <table class="form" id="tbcfmx" style="display:none">
                <tr>
                    <th class="formTitle">处方号：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="txtcfh" name="txtcfh" readonly="readonly" style="border:0px;color:#aaa"/>
                    </td>
                    <th class="formTitle">医生：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="txtys" name="txtys" readonly="readonly" style="border:0px;color:#aaa"/>
                    </td>
                    <th class="formTitle">科室：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="txtks" name="txtks" readonly="readonly" style="border:0px;color:#aaa"/>
                    </td>
                     <th class="formTitle">总计金额:</th>
                     <td class="formValue">
                         <input type="text" class="form-control" id="txtzje" name="txtzje" readonly="readonly" style="border:0px;color:#aaa"/>
                     </td>
            </table>
        </content>
    </ul>
    <div class="tab-content" style="margin-top:0%">
        <div class="tab-pane fade in active" id="newyj">
            <div class="rows" style="float:left;width:25%;">
                <table id="gridleftList"></table>
            </div>
            <div class="rows" style="float:left;width:74%;margin-left:5px;">
                <table id="gridrightList" style="float:left;width:93.5%;margin-left:5px;"></table>
            </div>

        </div>
        <div class="tab-pane fade" ;style="background-color: #fff; width:100%" id="yj">
            <table id="gridJSMXList"></table>
        </div>
    </div>
    @*<div style="background-color: #fff; margin-top:5px;">
        <table id="gridJSMXList"></table>
        @*<div id="gridJSMXListPager"></div>
    </div>*@
</form>

<script>
    $(function () {
        //浏览器窗口调整大小时重新加载jqGrid的宽
        $(window).resize(function () {
            initLayout("MyTabGrid");
        });
        //结算主记录
        gridJSListData();
    });

    //刷卡
    function SK() {
        $.modalAlert("功能正在开发中", 'warning');
        return false;
    }

    var medicalInsurance = '@(medicalInsurance)';
    //配置：日期筛选 是按收费日期，还是收费操作时间
    var useSfrqFilter = '@(useSfrqFilter)' == 'True';
    //门诊挂号结算查询
    function gridJSListData() {
        var gridSort = 'CreateTime asc';
        if (useSfrqFilter) {
            $('#thCZRQ').html('费用日期：');
            gridSort = 'sfrq asc';
        }
        //
        var $gridJsList = $("#gridJSList");
        $gridJsList.dataGrid({
            postData: getSearchPostData(),
            height: 150,
            url: "/OutpatientManage/OutpatientChargeQuery/SelectRegChargeQuery",
            colModel: [
                { label: 'jsnm', name: 'jsnm', hidden: true, align: 'left' },
                 {
                     label: '结算类型', name: 'jslx', width: 60, align: "left",
                     formatter: function (val) {
                         return $.enum.getDescByValue("EnumJslx", val);
                     }
                 },
                { label: '病例号', name: 'blh', width: 60, align: 'left' },
                { label: '姓名', name: 'xm', width: 80, align: 'left' },
                { label: '费用性质', name: 'brxzmc', width: 90, align: 'left' },
                { label: '发票号', name: 'fph', width: 80, align: 'left' },
                { label: '中心流水号', name: 'zxlsh', width: 80, align: 'left' },
                {
                    label: '结算金额', name: 'jszje', width: 70, align: 'left', formatter: function (cellvalue) {
                        return cellvalue ? cellvalue.toFixed(2) : "0.00";
                    }
                },
                {
                    label: '支付金额', name: 'jsxjzf', width: 70, align: 'left', formatter: function (cellvalue) {
                        return cellvalue ? cellvalue.toFixed(2) : "0.00";
                    }
                },
                {
                    label: '费用日期', name: 'sfrq', width: 100, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
                },
                { label: '收费人员', name: 'CreatorName', width: 80, align: 'left' },
                { label: '医生', name: 'jzys', width: 80, align: 'left' },
                {
                    label: '操作时间', name: 'CreateTime', width: 120, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                },
                { label: '退费员', name: 'tCreatorCode', align: 'left', hidden: true },
                {
                    label: "操作", name: "", width: 80, align: 'left',
                    formatter: function (cellvalue, options, rowobject) {
                        if (!(rowobject.jszje == 0)) {
                            var str = "";
                            if (medicalInsurance=="guian") {
                                str += '<a class="btn btn-default" title="收据明细" style="width: 26%;" onclick="printMxData(\'' + rowobject.jsnm + '\')">收据明细</a>  <a class="btn btn-default" title="发票补打" style="width: 26%;" onclick="printguianFp(\'' + rowobject.jsnm + '\')">发票补打</a>';
                            } else {
                                if ((!!regReportUrl && rowobject.jslx == '0') || (!!chargeReportUrl && rowobject.jslx == '2')) {
                                    str += '<a class="btn btn-default" title="收据明细" style="width: 20%;" onclick="printFp(\'' + rowobject.jsnm + '\',\'' + rowobject.jslx + '\',\'' + rowobject.brxzmc + '\')">收据</a>';
                                    //str += '<a class="btn btn-default" title="打印明细" style="width: 38%;" onclick="printFpdymx(\'' + rowobject.jsnm + '\')">打印明细</a>';
                                }
                                else {
                                    //否则不打印
                                }
                                if (!!!rowobject.fph) {
                                    //可以财务补打
                                    if ('@(invoicePrintMethod)' == 'ActiveX') {
                                        //财务补打按钮
                                        str += '&nbsp;<a class="btn btn-default" title="财务打印" style="width: 40%;" onclick="axFpBuda(\'' + rowobject.jsnm + '\')">财务补打</a>';
                                    }
                                }
                            }

                            return str;
                        }
                        else {
                            //否则不打印
                            return '';
                        }
                    }
                },
            ],
            pager: "#gridPager",
            sortname: gridSort,
            viewrecords: true,
            onSelectRow_page: function (rowid) {
                btn_selectrow();
            },
            gridComplete: function (gridJszbList) {
                jszbList = null;
                if (gridJszbList && gridJszbList.rows) {
                    jszbList = gridJszbList.rows;
                }
            }
        });
        //注释
        $("#btn_search").click(function () {
            $('#gridJSMXList').jqGrid("clearGridData");//先清空明细
            $('#gridleftList').jqGrid("clearGridData");//先清空明细
            $('#gridrightList').jqGrid("clearGridData");//先清空明细
            $("#tbcfmx").attr("style", "display:none;");
            $gridJsList.jqGrid('setGridParam', {
                postData: getSearchPostData(),
                url: '/OutpatientManage/OutpatientChargeQuery/SelectRegChargeQuery',
                page: 1,
            }).trigger('reloadGrid');
        });
    }

    var jszbList = null;

    function getSearchPostData() {
        var kh = "";//$("#txtkh").val();
        var fph = $("#txtfph").val();
        var jsfph = $("#txtjsfph").val();
        var xm = $("#txtxm").val();
        var syy = $("#txtsyy").val();
        var zxlsh = $("#txtzxlsh").val();
        var createTimestart = useSfrqFilter ? null : $("#txtCreateTimestart").val();
        var createTimeEnd = useSfrqFilter ? null : $("#txtCreateTimeEnd").val();
        var sfrqTimestart = useSfrqFilter ? $("#txtCreateTimestart").val() : null;
        var sfrqTimeEnd = useSfrqFilter ? $("#txtCreateTimeEnd").val() : null;
        return {
            kh: kh, fph: fph, xm: xm, syy: syy, CreateTimestart: createTimestart, CreateTimeEnd: createTimeEnd
            , sfrqTimestart: sfrqTimestart, sfrqTimeEnd: sfrqTimeEnd, zxlsh: zxlsh
        };
    };
    function uniq(dataList, byName) {
        var result = [];
        var tem = {};
        for (var i = 0; i < dataList.length; i++) {
            if (!tem[dataList[i][byName]]) {
                result.push(dataList[i]);
                tem[dataList[i][byName]] = 1;
            }
        }
        return result;
    }

    //单击事件
    var jsmxarrlist;
    function btn_selectrow() {
        //每次单击，先清空上一条明细 和合计
        $('#gridleftList').jqGrid("clearGridData");
        $('#gridJSMXList').jqGrid("clearGridData");
        $('#gridrightList').jqGrid("clearGridData");
        $("#tbcfmx").attr("style", "display:none;");
        $.najax({
            type: "POST",
            url: "/OutpatientManage/OutpatientChargeQuery/GetRecordsByJsnm",
            data: { jsnm: $("#gridJSList").jqGridRowValue().jsnm },
            dataType: "json",
            success: function (ajaxresp) {
                $("#table_HJ").remove();
                debugger;
                $('#gridJSMXList').newtouchLocalDataGrid(null, ajaxresp.data.ghRecordsDetails);
                jsmxarrlist = ajaxresp.data.ghRecordsDetails;
                var fldata = uniq(ajaxresp.data.ghRecordsDetails,"dlmc");
                $('#gridleftList').newtouchLocalDataGrid(null, fldata);
                //动态加载合计信息
                afterCompleteFunction();
                //$("#HjDiv").append("<table class='form' id='table_HJ'>");
                $("#table_HJ").append(" <tr>");
                //加载页面下方的费用大类合计
                //for (i = 0; i < ajaxresp.data.dlhj.length; i++) {
                //    $("#table_HJ").append("<th class='formTitle'>" + ajaxresp.data.dlhj[i].dlmc + "</th>");
                //    $("#table_HJ").append("<td class='formValue'><label>" + ajaxresp.data.dlhj[i].jehj.toFixed(2) + "</label></td>");
                //}
                //$("#table_HJ").append(" </tr>");
                //$("#table_HJ").append(" </table>");
            }
        });
    }

    $('#gridleftList').newtouchLocalDataGrid({
        height: $(window).height() - 370,
        unwritten: false,
        colModel: [
            { label: '类型', name: 'dlmc', width: 70 },
            { label: '发票号码', name: 'fph', width: 80, align: 'left' },
            {
                label: '状态', name: 'jszt', width: 60, align: 'left', formatter: function (cellvalue) {
                    return cellvalue=="2" ? "已退" : "已结";
                }
            },
        ],
        onSelectRow: function (rowid, status) {
            debugger;
            $('#gridrightList').jqGrid("clearGridData");
            var gridId = $("#gridleftList").jqGridRowValue().dlmc;
            var fllist = jsmxarrlist.filter(item => item.dlmc == gridId)
            $('#gridrightList').newtouchLocalDataGrid(null, fllist);
            $("#tbcfmx").attr("style", "display:block;");
            $("#txtcfh").val(fllist[0].cfh);
            $("#txtys").val(fllist[0].ysmc);
            $("#txtks").val(fllist[0].ksmc);
            let sum=0;
            var dds = fllist.map(function (item) {
                sum += item.je;
            });
            $("#txtzje").val(sum);
        }
    })

    $('#gridrightList').newtouchLocalDataGrid({
        height: $(window).height() - 370,
        unwritten: false,
        colModel: [
            { label: '费用名称', name: 'ypmc', width: 130 },
            { label: '规格', name: 'gg', width: 80 },
            { label: '单位', name: 'dw', width: 70, align: 'left' },
            { label: '单价', name: 'dj', width: 70, align: 'left' },
            { label: '数量', name: 'sl', width: 70, align: 'left' },
            { label: '金额', name: 'je', width: 70, align: 'left' },
            {
                label: '自负比例', name: 'zfbl', width: 70, align: 'left', formatter: function (cellvalue) {
                    return cellvalue.toFixed(3);
                }
            },
            { label: '用法', name: 'pc', width: 70, align: 'left' },
        ]
    })

    //门诊结算明细 jGrid声明
    $('#gridJSMXList').newtouchLocalDataGrid({
        height: $(window).height() - 370,
        //caption: "门诊结算明细",
        unwritten: false,
        colModel: [
            { label: 'jsmxnm', name: 'jsmxnm', hidden: true, key: true },
            { label: '处方号', name: 'cfh', width: 130 },
            { label: '项目代码', name: 'sfxm', width: 100, align: 'left', hidden: true },
            { label: '项目名称', name: 'ypmc', width: 220, align: 'left' },
            { label: '费用大类', name: 'dlmc', width: 80, align: 'left' },
            { label: '单位', name: 'dw', width: 50, align: 'left' },
            {
                label: '单价', name: 'dj', width: 60, align: 'left', formatter: function (cellvalue) {
                    return cellvalue ? cellvalue.toFixed(4) : "0.00";
                }
            },
            { label: '计费数量', name: 'sl', width: 60, align: 'left' },
            {
                label: '计费金额', name: 'je', width: 80, align: 'left', formatter: function (cellvalue) {
                    return cellvalue ? cellvalue.toFixed(2) : "0.00";
                }
            },
            { label: '开立数量', name: 'klsl', width: 60, align: 'left' },
            {
                label: '开立金额', name: 'klje', width: 80, align: 'left', formatter: function (cellvalue) {
                    return cellvalue ? cellvalue.toFixed(2) : "0.00";
                }
            },
            { label: '已退数量', name: 'ytsl', width: 60, align: 'left' },
            {
                label: '已退金额', name: 'ytje', width: 80, align: 'left', formatter: function (cellvalue) {
                    return cellvalue ? cellvalue.toFixed(2) : "0.00";
                }
            },
            { label: '开方医生', name: 'ysmc', width: 70, align: 'left' }

        ],
        gridComplete: function (gridJszbList) {
            $("#gbox_gridJSMXList").attr("style", $(window).width());
        },
        pager: "#gridJSMXListPager",
        sortname: 'ypmc asc',
        viewrecords: true,

    });

    //已退/重打 背景色为红色
    function afterCompleteFunction() {
        var ids = $("#gridJSMXList").getDataIDs();
        for (i = 0; i < ids.length; i++) {
            var rowData = $("#gridJSMXList").getRowData(ids[i]);
            if (rowData.ytje > 0) {
                $("#gridJSMXList tr[id=" + ids[i] + "]").find("td").css("background-color", "rgb(255,228,196)"); //255,218,185
            }
        }
    }


    //操作人
    $("#btnsyy").click(function () {
        $.modalOpen({
            id: "FormOutpatSFCZYUsers",
            title: "选择操作员",
            url: "/SystemManage/User/Selector?from=mzshoufeicaozuoyuan&organizeId=" + '@curOpr.OrganizeId' + "&isExpand=true&callbackType=json&single=true",
            width: "300px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick(function (data) {
                    userStaffTreeCallback(data);
                });
            }
        });
    });
    //用户人员树回调方法
    function userStaffTreeCallback(data) {
        $("#txtsyy").val(data[0].Code);
    }

    var regReportUrl = '@Html.Raw(regReportUrl)';
    var chargeReportUrl = '@Html.Raw(chargeReportUrl)';
    var OutpatientChargeDetail = '@Html.Raw(OutpatientChargeDetail)';
    var ZFinvoiceReportUrl = '@Html.Raw(ZFinvoiceReportUrl)';

    function printFp(jsnm, jslx, brxz) {
        //打印HIS收据（当前非发票）
        var uri;
        var orgId = '@(ViewBag.OrgId)';
        uri = '@reportUrl' + "?tempCode=02" + "&hospitalCode=" + orgId + "&jsnm=" + jsnm + "&systemCode=" + '@reportSystemCode';
        if (jslx == 0) {
            uri = '@reportUrl' + "?tempCode=01" + "&hospitalCode=" + orgId + "&jsnm=" + jsnm + "&systemCode=" + '@reportSystemCode';
        }
        if (uri) {
            window.open(uri,
                "_blank",
                "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
        }
    };





    function printguianFp(jsnm) {

        var uri;
        uri = chargeReportUrl + "&jsnm=" + jsnm ;
        if (uri) {
            window.open(uri,
                "_blank",
                "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
        }
    }

    function printMxData(jsnm) {
        var uri;
        uri = OutpatientChargeDetail + "&jsnm=" + jsnm;
        if (uri) {
            window.open(uri,
                "_blank",
                "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
        }
    }

    var curUserCode = '@(ViewBag.CurUserCode)';
    //打印明细
    var srcUrl = "";
    function printFpdymx(jsnm) {

        var reportServerHOST = '@(ViewBag.ReportServerHOST)';
        var orgId = '@(ViewBag.OrgId)';

        var urldy = "/ReportServer/Pages/ReportViewer.aspx?%2fHIS.Report.1%2f收费查询明细表&rs:Command=Render&rc:Stylesheet=MyStyleSheet&jsnm=" + jsnm + "&OrganizeId=" + orgId + "&orgId=" + orgId + "&curUserCode=" + curUserCode;
        if (urldy.StartWith('/')) {
            urldy = urldy.substr(1);
        }
        srcUrl= urldy;
        srcUrl = reportServerHOST + srcUrl;

        window.open(srcUrl);
    }


    $(function () {
        var h = $(window).height() - 55
        $('#layout iframe').css('height', h);
        setTimeout(function () { }, 100);
    });


</script>
@if (invoicePrintMethod == "ActiveX")
{
    <script type="text/javascript">
        //AX发票补打
        function axFpBuda(jsnm) {
            $.modalConfirm("确认补打财务发票", function (flag) {
                if (!flag) {
                    return;
                }
                else {
                    setTimeout("doAxFpBuda(" + jsnm + ")", 50);
                }
            });
        }

        function doAxFpBuda(jsnm) {
            if (jszbList) {
                var matched = false;
                var newTempPatModel = {};
                var newJszbInfo = {};
                $.each(jszbList, function () {
                    if (this.jsnm == jsnm) {
                        matched = true;
                        newTempPatModel.sbbh = this.sbbh;
                        newTempPatModel.xm = this.xm;
                        newTempPatModel.mzh = this.mzh;
                        newTempPatModel.ksmc = this.ghksmc;
                        newTempPatModel.ysmc = this.ghysmc;

                        newJszbInfo.jsnm = this.jsnm;
                        newJszbInfo.ybjsh = this.ybjsh;
                        newJszbInfo.jszje = this.jszje;
                        newJszbInfo.jsxjzf = this.jsxjzf;
                        newJszbInfo.zffsmcstr = this.zffsmcstr;
                        newJszbInfo.YBZHZC = this.YBZHZC;
                        newJszbInfo.JBYE = this.JBYE;
                        newJszbInfo.GBYE = this.GBYE;
                    }
                });
                if (matched) {
                    //1、打印新发票
                    axPrintInvoiceBySettInfo(newTempPatModel, newJszbInfo);
                }
            }
        }

        //根据结算信息打印AX发票
        //var newTempPatModel = { xm: null, mzh: null, ksmc: null, ysmc: null};
        //var newJszbInfo = { jsnm: null, ybjsh: null, jszje: null, jsxjzf: null, YBZHZC: null, JBYE: null, GBYE: null };
        function axPrintInvoiceBySettInfo(paramNewTempPatModel, paramNewJszbInfo) {
            newTempPatModel = $.deepClone.clone(paramNewTempPatModel);
            newJszbInfo = $.deepClone.clone(paramNewJszbInfo);
            if (newJszbInfo && !!newJszbInfo.jsnm && !isNaN(newJszbInfo.jszje) && parseFloat(newJszbInfo.jszje) > 0 && !(newJszbInfo.ytw == true)) {
                if ('@(invoicePrintMethod)' == 'ActiveX') {
                    //开新发票
                    $.najax({
                        type: "POST",
                        url: "/OutpatientManage/OutpatientRefund/RefundableDetailQuery?jsnm=" + newJszbInfo.jsnm,
                        dataType: "json",
                        loading: false,
                        success: function (detailList) {
                            if (detailList && detailList.length) {
                                //activeX打印
                                var axFpInitJson = {};
                                axFpInitJson.InfoClientName = newTempPatModel.xm;
                                axFpInitJson.InfoClientTaxCode = '';
                                axFpInitJson.InfoClientBankAccount = '';
                                axFpInitJson.InfoClientAddressPhone = '';   //mobile?
                                axFpInitJson.InfoSellerBankAccount = '101290001017805087';
                                axFpInitJson.InfoSellerAddressPhone = '常熟市长江西路 52491397';
                                axFpInitJson.InfoTaxRate = 0;
                                var theFpNote = "";
                                if (!!newTempPatModel.sbbh) {
                                    theFpNote += '社保编号：' + newTempPatModel.sbbh + ";";
                                }
                                theFpNote += '就诊序号：' + newTempPatModel.mzh + ";";
                                theFpNote += 'HIS结算号：' + newJszbInfo.jsnm + ";";
                                if (!!newJszbInfo.ybjsh) {
                                    theFpNote += '医保结算号：' + newJszbInfo.ybjsh + ";";
                                }
                                if (newTempPatModel.ksmc) {
                                    theFpNote += newTempPatModel.ksmc + ";";
                                }
                                if (newTempPatModel.ysmc) {
                                    theFpNote += newTempPatModel.ysmc + ";";
                                }
                                if (!isNaN(newJszbInfo.jszje) && newJszbInfo.jszje != null && newJszbInfo.jszje != undefined) {
                                    theFpNote += '总金额：' + parseFloat(newJszbInfo.jszje).toFixed(2) + ";";
                                }
                                if (!isNaN(newJszbInfo.jsxjzf) && newJszbInfo.jsxjzf != null && newJszbInfo.jsxjzf != undefined) {
                                    theFpNote += '现金支付：' + parseFloat(newJszbInfo.jsxjzf).toFixed(2) + ";";
                                    if (parseFloat(newJszbInfo.jsxjzf) > 0 && !!newJszbInfo.zffsmcstr) {
                                        theFpNote += '现金支付方式：' + newJszbInfo.zffsmcstr + ";";
                                    }
                                }
                                if (!isNaN(newJszbInfo.YBZHZC) && newJszbInfo.YBZHZC != null && newJszbInfo.YBZHZC != undefined) {
                                    theFpNote += '账户支出：' + parseFloat(newJszbInfo.YBZHZC).toFixed(2) + ";";
                                }
                                if (!isNaN(newJszbInfo.JBYE) && newJszbInfo.JBYE != null && newJszbInfo.JBYE != undefined) {
                                    theFpNote += '个人账户余额：' + parseFloat(newJszbInfo.JBYE).toFixed(2) + ";";
                                }
                                if (!isNaN(newJszbInfo.GBYE) && newJszbInfo.GBYE != null && newJszbInfo.GBYE != undefined) {
                                    theFpNote += '公补账户余额：' + parseFloat(newJszbInfo.GBYE).toFixed(2) + ";";
                                }
                                axFpInitJson.InfoNotes = theFpNote.substring(0, (theFpNote.length - 1));
                                axFpInitJson.InfoInvoicer = '@(opr.UserName)';
                                axFpInitJson.InfoChecker = '';
                                axFpInitJson.InfoCashier = '';
                                axFpInitJson.InfoListName = '';
                                axFpInitJson.InfoBillNumber = '';
                                var axFpInvoiceItemJson = [];
                                $.each(detailList, function () {
                                    if (parseFloat(this.dj) == 0 || parseFloat(this.sl) == 0) {
                                        return; //跳过金额0的
                                    }
                                    if (!isNaN(this.sl) && parseInt(this.sl) > 0) {
                                        axFpInvoiceItemJson.push({
                                            ListGoodsName: this.mc,
                                            ListTaxItem: "4001",
                                            ListStandard: "",
                                            ListUnit: this.dw,
                                            ListNumber: this.sl,
                                            ListPrice: parseFloat(this.dj).toFixed(2),
                                            ListAmount: parseFloat(this.jsmxje).toFixed(2),
                                            ListPriceKind: 0,
                                            ListTaxAmount: 0,
                                        });
                                    }
                                });
                                //activeX 医保交易打印
                                //activeX 自费打印
                                axPrintInvoice(newJszbInfo.jsnm, axFpInitJson, axFpInvoiceItemJson);
                            }
                        }
                    });
                }
                //else 应该已在外部处理 打印RS报表
            }
            //else不需要打印新发票
        }

        //AX发票打印
        function axPrintInvoice(jsnm, axFpInitJson, axFpInvoiceItemJson) {
            var printInvoiceReturn = $.printAX.PrintInvoice(JSON.stringify(axFpInitJson), JSON.stringify(axFpInvoiceItemJson));
            if (printInvoiceReturn && printInvoiceReturn.Code == 0) {
                //发票打印，返回成功了
                var axFpInfo = printInvoiceReturn.Data;
                if (axFpInfo.InfoNumber) {
                    //更新结算主表的fph字段
                    $.najax({
                        type: "POST",
                        data: {
                            jsnm: jsnm,
                            fph: axFpInfo.InfoNumber
                        },
                        url: "/OutpatientManage/OutpatCharge/UpdateSettedFph",
                        dataType: "json",
                        loading: false,
                        success: function (ajaxresp) {

                        }
                    });
                }
            }
            else {
                $.modalAlert(printInvoiceReturn.ErrorMsg, 'error');
                return;
            }
        }
    </script>
}
